import React from 'react'
import { NavBar } from 'antd-mobile';
import {InputItem,TextareaItem,Button} from 'antd-mobile'
import AvatarSelector from '../../components/AvatarSelector/avatarSelector'
import {connect} from 'react-redux'
import {update} from '../../redux/user.redux'
import {Redirect} from 'react-router-dom'
@connect(
    state=>state.user,
    {update}
)
class Geniusinfo extends React.Component{
    constructor(props){
        super(props)
        this.state={
            title:'',
            desc:'',
        }
    }
    onChange(key,val){
        this.setState({
            [key]:val
        })
    }
    render(){
        const path=this.props.location.pathname;
        const redirect=this.props.redirectTo
        console.log(this.props.redirectTo);
        
        return (
            <div>
                {redirect&&redirect!==path?<Redirect to={this.props.redirectTo}></Redirect> :null}
                <NavBar mode="dark">牛人信息完善页面</NavBar>
                <AvatarSelector
                    selectAvatar={(imgname)=>{
                        this.setState({
                            avatar:imgname
                        })
                    }}
                ></AvatarSelector>
                <InputItem onChange={(v)=>{this.onChange('title',v)}}>
                    求职职位
                </InputItem>
                <TextareaItem autoHeight title='个人简介' rows={3} onChange={(v)=>{this.onChange('desc',v)}}>
                    
                </TextareaItem>
                <Button 
                    onClick={()=>{this.props.update(this.state)}}
                    type="primary">保存</Button>
            </div>
        )
    } 
}
export default Geniusinfo